/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.cacheplugins  
 */
package com.apache.bid.service.cacheplugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.common.cache.BidCacheManager;
import com.apache.bid.common.vo.BidItemCacheVo;
import com.apache.bid.entity.BidItem;
import com.apache.bid.manager.BidItemManager;
import com.apache.cache.util.Validator;

/**
 * description:  修改标的图片接口实现（对接图片库有实体设置主图操作）
 * @author Hou Dayu 创建时间：2016-5-13  
 * 
 */
public class ItemEditPicUrlPluginImpl implements PluginConnector {

	private BidItemManager bidItemManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		String itemId = String.valueOf(param.getParams("objId"));
		if (Validator.isNull(itemId)) {
			entity.setResult("false");
			entity.setMessage("缺少方法参数,方法执行失败");
		}
		String picUrl = String.valueOf(param.getParams("picUrl"));
		BidItem item = new BidItem();
		item.setItemId(itemId);
		item.setPicUrl(picUrl);
		item.setPicUrlSmall(picUrl);
		param.setObj(item);
		param.setMethodKey("");
		boolean mark = bidItemManager.editInfo(param);
		if (mark) {
			BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("item");
			if (cache.checkCacheObject(BidCacheManager.item_prefix + itemId)) {
				BidItemCacheVo itemVo = (BidItemCacheVo) cache
						.getCacheObjectByKey(BidCacheManager.item_prefix + itemId);
				itemVo.setPicUrl(picUrl);
				itemVo.setPicUrlSmall(picUrl);
				cache.updateCacheObject(itemVo);
			}
			entity.setResult("true");
			entity.setEntity("true");
			entity.setMessage("操作成功");
		}
		return entity;
	}

	public void setBidItemManager(BidItemManager bidItemManager) {
		this.bidItemManager = bidItemManager;
	}

}
